I have recently purchased a kanalog. I am planing to use it with some brushless servos and other components that I don't yet have ready. In the mean time I would like to use it with my current setup to control a VFD. The current setup is steppers with open collector step direction drives.
So what I plan to do to get up and running is connect the drives to JP5. I think that all I need to do is change the OutputChan0 from 0-2 (respectively) to 4-6. Is there anything else that needs to be done?
#include "KMotionDef.h"
#define TMP 10
#include "KflopToKMotionCNCFunctions.c"
#define MSPI 80000000
#define ZMIN -5
#define ZMAX 0
#define XMIN 0
#define XMAX 17.5
#define YMIN 0
#define YMAX 11
#define CNTS_PER_INCH_X 2000
#define CNTS_PER_INCH_Y 2000
#define CNTS_PER_INCH_Z 2000
#define X_TC 0
#define Y_TC 0
#define Z_TC 0
#define X 0
#define Y 1
#define Z 2
#define MaxY 21000
#define MinY -100
#define MaxZ 100
#define MinZ -9700
#define MaxX 34500
#define MinX -100
#define SpeedX 3000
#define SpeedY 3000
#define SpeedZ 2000
#define AccelX 8000
#define AccelY 8000
#define AccelZ 3000
#define JerkX 8000000
#define JerkY 8000000
#define JerkZ 3000000
double DROx, DROy, DROz, DROa, DROb, DROc;
void SetSoftLim(int);
void home(void);
void center(void);
int SLST = 1;
main()
{
//swap Y with X, then swap X with Z, then swap Z with Y
EnableAxisDest(X,ch0->Dest); //X
EnableAxisDest(Y,ch1->Dest); //Y
EnableAxisDest(Z,ch2->Dest); //Z
// EnableAxisDest(Y,12919); //y
// EnableAxisDest(1,0); //z
// EnableAxisDest(2,22640); //x
SetSoftLim(1);
FPGA(STEP_PULSE_LENGTH_ADD) = 63;
DefineCoordSystem(X,Y,Z,-1);
ch0->InputMode=NO_INPUT_MODE;
ch0->OutputMode=STEP_DIR_MODE;
ch0->Vel=SpeedX;
ch0->Accel=AccelX;
ch0->Jerk=JerkX;
ch0->P=1;
ch0->I=0;
ch0->D=0;
ch0->FFAccel=0;
ch0->FFVel=0;
ch0->MaxI=200;
ch0->MaxErr=1e+006;
ch0->MaxOutput=200;
ch0->DeadBandGain=1;
ch0->DeadBandRange=0;
ch0->InputChan0=0;
ch0->InputChan1=0;
ch0->OutputChan0=0;
//ch0->LimitSwitchNegBit=48;
//ch0->LimitSwitchPosBit=49;
ch0->MasterAxis=-1;
ch0->InputGain0=1;
ch0->InputGain1=1;
ch0->InputOffset0=0;
ch0->InputOffset1=0;
ch0->OutputGain=-1;
ch0->OutputOffset=0;
ch0->SlaveGain=1;
ch0->BacklashMode=BACKLASH_OFF;
ch0->BacklashAmount=0;
ch0->BacklashRate=0;
ch0->invDistPerCycle=1;
ch0->Lead=0;
ch0->MaxFollowingError=1000000000;
ch0->StepperAmplitude=20;
ch0->iir[0].B0=1;
ch0->iir[0].B1=0;
ch0->iir[0].B2=0;
ch0->iir[0].A1=0;
ch0->iir[0].A2=0;
ch0->iir[1].B0=1;
ch0->iir[1].B1=0;
ch0->iir[1].B2=0;
ch0->iir[1].A1=0;
ch0->iir[1].A2=0;
ch1->InputMode=NO_INPUT_MODE;
ch1->OutputMode=STEP_DIR_MODE;
ch1->Vel=SpeedY;
ch1->Accel=AccelY;
ch1->Jerk=JerkY;
ch1->P=1;
ch1->I=0;
ch1->D=0;
ch1->FFAccel=0;
ch1->FFVel=0;
ch1->MaxI=200;
ch1->MaxErr=1e+006;
ch1->MaxOutput=200;
ch1->DeadBandGain=1;
ch1->DeadBandRange=0;
ch1->InputChan0=0;
ch1->InputChan1=0;
ch1->OutputChan0=1;
// ch1->LimitSwitchNegBit=50;
//ch1->LimitSwitchPosBit=51;
ch1->MasterAxis=-1;
ch1->InputGain0=1;
ch1->InputGain1=1;
ch1->InputOffset0=0;
ch1->InputOffset1=0;
ch1->OutputGain=1;
ch1->OutputOffset=0;
ch1->SlaveGain=1;
ch1->BacklashMode=BACKLASH_OFF;
ch1->BacklashAmount=0;
ch1->BacklashRate=0;
ch1->invDistPerCycle=1;
ch1->Lead=0;
ch1->MaxFollowingError=1000000000;
ch1->StepperAmplitude=20;
ch1->iir[0].B0=1;
ch1->iir[0].B1=0;
ch1->iir[0].B2=0;
ch1->iir[0].A1=0;
ch1->iir[0].A2=0;
ch1->iir[1].B0=1;
ch1->iir[1].B1=0;
ch1->iir[1].B2=0;
ch1->iir[1].A1=0;
ch1->iir[1].A2=0;
ch2->InputMode=NO_INPUT_MODE;
ch2->OutputMode=STEP_DIR_MODE;
ch2->Vel=SpeedZ;
ch2->Accel=AccelZ;
ch2->Jerk=JerkZ;
ch2->P=1;
ch2->I=0;
ch2->D=0;
ch2->FFAccel=0;
ch2->FFVel=0;
ch2->MaxI=200;
ch2->MaxErr=1e+006;
ch2->MaxOutput=200;
ch2->DeadBandGain=1;
ch2->DeadBandRange=0;
ch2->InputChan0=0;
ch2->InputChan1=0;
ch2->OutputChan0=2;
ch2->MasterAxis=-1;
ch2->InputGain0=1;
ch2->InputGain1=1;
ch2->InputOffset0=0;
ch2->InputOffset1=0;
ch2->OutputGain=1;
ch2->OutputOffset=0;
ch2->SlaveGain=1;
ch2->BacklashMode=BACKLASH_OFF;
ch2->BacklashAmount=0;
ch2->BacklashRate=0;
ch2->invDistPerCycle=1;
ch2->Lead=0;
ch2->MaxFollowingError=1000000000;
ch2->StepperAmplitude=20;
ch2->iir[0].B0=1;
ch2->iir[0].B1=0;
ch2->iir[0].B2=0;
ch2->iir[0].A1=0;
ch2->iir[0].A2=0;
ch2->iir[1].B0=1;
ch2->iir[1].B1=0;
ch2->iir[1].B2=0;
ch2->iir[1].A1=0;
ch2->iir[1].A2=0;
ClearBit(48); // soft limits
ClearBit(49); // home x and y
ClearBit(50); // center x
ClearBit(51); // center y
ClearBit(52); // home z
persist.UserData[10] = 0; //set current tool to zero force tool change on first M6
int lasty = ch1->Dest;
int lastz = ch2->Dest;
int lastx = ch0->Dest;
while(1){
if(ReadBit(48)) { //soft limits disable and manual home sequence
ClearStopImmediately();
SetSoftLim(0); //disable soft limits
ClearBit(48);
while(~ReadBit(48)){
home();
WaitNextTimeSlice();
}
ClearBit(48);
SetSoftLim(1);
}
home();
center();
WaitNextTimeSlice();
}
}
void SetSoftLim(int SLST){
if(SLST) {
ch0->SoftLimitPos=MaxX; //y
ch0->SoftLimitNeg=MinX; //y
ch1->SoftLimitPos=MaxY; //z
ch1->SoftLimitNeg=MinY; //z
ch2->SoftLimitPos=MaxZ; //x
ch2->SoftLimitNeg=MinZ; //x
}
else{
ch0->SoftLimitPos= 80000; //y
ch0->SoftLimitNeg=-80000; //y
ch1->SoftLimitPos=80000; //z
ch1->SoftLimitNeg=-80000; //z
ch2->SoftLimitPos=80000;
ch2->SoftLimitNeg=-80000;
}
return;
}
void home (void){
if(ReadBit(49)){ //home sequence X,Y
ClearStopImmediately();
EnableAxisDest(0,0);
EnableAxisDest(1,0);
ClearBit(49);
}
if(ReadBit(52)){ //home sequence Z
ClearStopImmediately();
EnableAxisDest(2,0);
ClearBit(52);
}
return;
}
void center(void){
if(ReadBit(50)){ //center x
GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);
DoPCFloat(PC_COMM_SET_X, DROx/2);
ClearBit(50);
}
if(ReadBit(51)){ //center y
GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);
DoPCFloat(PC_COMM_SET_Y, DROy/2);
ClearBit(51);
}
return;
}